package linkwechat.service.systemservice;

import linkwechat.mapper.system.PerSonalMapper;
import linkwechat.pojo.ReturnData;
import linkwechat.pojo.ReturnEnum;
import linkwechat.pojo.SysUseres;
import linkwechat.util.Bcrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class PerSonalService {
    @Autowired
    PerSonalMapper perSonalMapper;

    public ReturnData UpdTx(String upload, Long id) {
        Integer i = perSonalMapper.UpdTx(upload, id);
         if (i>0){
             return ReturnData
                     .builder()
                     .code(ReturnEnum.MODIFY_SUCCEED.getCode())
                     .msg(ReturnEnum.MODIFY_SUCCEED.getMsg())
                     .data(upload)
                     .build();
         }
        return ReturnData
                .builder()
                .data(0)
                .build();
    }

    public ReturnData UpdFeRzl(SysUseres sysUseres) {
        Integer i = perSonalMapper.UpdGeRzl(sysUseres);
        if (i>0){
            return ReturnData
                    .builder()
                    .code(ReturnEnum.MODIFY_SUCCEED.getCode())
                    .msg(ReturnEnum.MODIFY_SUCCEED.getMsg())
                    .data(i)
                    .build();
        }
        return ReturnData
                .builder()
                .data(0)
                .build();
    }

    public ReturnData UpdPwd(String pwd, Long id) {
        String s = Bcrypt.BaryPass(pwd);
        Integer i = perSonalMapper.UpdPwd(s,id);
        if (i>0){
            return ReturnData
                    .builder()
                    .code(ReturnEnum.MODIFY_SUCCEED.getCode())
                    .msg(ReturnEnum.MODIFY_SUCCEED.getMsg())
                    .data(i)
                    .build();
        }
        return ReturnData
                .builder()
                .data(0)
                .build();
    }

}
